﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace FRL.DebtChased.Silverlight.Library
{

	/// <summary>
	/// Declaration of HeadingBarCtrl class
	/// Heading bar goes between child controls, to make different parts
	/// of the screen.  Includes arrow for raising and dropping animated sections.
	/// </summary>
	public partial class HeadingBarCtrl : UserControl
	{

		/////////////////////////////////////////////////////////////
		// Delegates and events

		public event EventHandler ExpandChange;

		/////////////////////////////////////////////////////////////
		// Attributes

		public string Label
		{
			get { return tbLabel.Text; }
			set { tbLabel.Text = value; }
		}

		private bool m_bShowButtons = false;
		public bool ShowButtons
		{
			get { return m_bShowButtons; }
			set { m_bShowButtons = value; _setupControls(); }
		}

		private bool m_bIsArrowUp = true;
		public bool IsArrowUp
		{
			get { return m_bIsArrowUp; }
			set { 
				m_bIsArrowUp = value;
				if (m_bIsArrowUp)
					(Resources["spinButtonUp"] as Storyboard).Begin();
				else
					(Resources["spinButtonDown"] as Storyboard).Begin();
			}
		}

		private bool m_bIsHighlighted = false;
		public bool IsHighlighted
		{
			get { return m_bIsHighlighted; }
			set { 
				m_bIsHighlighted = value;
				if (m_bIsHighlighted)
					LayoutRoot.Background = this.Resources["SecondaryBrush"] as SolidColorBrush;
				else
					LayoutRoot.Background = new SolidColorBrush(Colors.White);
			}
		}

		/////////////////////////////////////////////////////////////
		// Construction

		public HeadingBarCtrl()
		{

			// Initialize resources
			InitializeComponent();

			// Setup controls
			_setupControls();

		}

		/////////////////////////////////////////////////////////////
		// Event handlers

		private void butToggleExpand_Click(object sender, RoutedEventArgs e)
		{

			// Pass event back to owner
			if (ExpandChange != null)
				ExpandChange(this, new EventArgs());

		}

		/////////////////////////////////////////////////////////////
		// Operations

		private void _setupControls()
		{

			// Show/hide controls
			stackButtons.Visibility = m_bShowButtons ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed;

		}

	}

}
